package com.jhhc.StormSurgeForecast.StormSurge.Uitl;

import com.jhhc.StormSurgeForecast.StormSurge.Pojo.GZABO.CalParaInfo;
import com.jhhc.StormSurgeForecast.StormSurge.Pojo.GZABO.ColourInfo;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class JudgeUtil {
    //类型判断方法
    public static String typeClassification(String dtnm){
        int immersedTube = dtnm.indexOf("E");
        int pier = dtnm.indexOf("桥墩");
        int artificialIsland = dtnm.indexOf("岛");
        if (immersedTube != -1) {
            return "沉管";
        }else if (pier != -1) {
            return "桥墩";
        }else if (artificialIsland != -1) {
            return "填充岛屿";
        }else {
            return null;
        }
    }

    /**
     * 沉管覆盖土厚度HO取值
     * @param number 沉管编号
     * @return 沉管编号对用HO值
     */
    public static double EnJudge(Integer number){
        if (number == 1) { return 0.00; }
        if (number == 2) { return 0.00; }
        if (number == 3) { return 0.00; }
        if (number == 4) { return 0.00; }
        if (number == 5) { return 0.06; }
        if (number == 6) { return 0.19; }
        if (number == 7) { return 0.10; }
        if (number == 8) { return 0.22; }
        if (number == 9) { return 0.38; }
        if (number == 10) { return 1.13; }
        if (number == 11) { return 2.02; }
        if (number == 12) { return 2.17; }
        if (number == 13) { return 1.38; }
        if (number == 14) { return 2.22; }
        if (number == 15) { return 4.40; }
        if (number == 16) { return 6.48; }
        if (number == 17) { return 7.68; }
        if (number == 18) { return 9.09; }
        if (number == 19) { return 10.10; }
        if (number == 20) { return 11.00; }
        if (number == 21) { return 10.91; }
        if (number == 22) { return 10.41; }
        if (number == 23) { return 8.92; }
        if (number == 24) { return 7.72; }
        if (number == 25) { return 6.81; }
        if (number == 26) { return 7.04; }
        if (number == 27) { return 6.31; }
        if (number == 28) { return 4.21; }
        if (number == 29) { return 0.48; }
        if (number == 30) { return 0.10; }
        if (number == 31) { return 0.00; }
        if (number == 32) { return 0.00; }
        if (number == 33) { return 0.00; }
        return -1.0;
    }
    //色彩判断
    public static short colorJudge1(int colors){
        if (colors <= -200){return 1;}
        if (colors <= -100) { return 2; }
        if (colors <= -50){ return 3; }
        if (colors <= 0){ return 4; }
        if (colors <= 50){ return 5; }
        if (colors <= 100){ return 6; }
        if (colors <= 150){ return 7; }
        if (colors <= 200){ return 8; }
        if (colors <= 250){ return 9; }
        if (colors <= 300){ return 10; }
        if (colors <= 400){ return 11; }
        return -1;
    }
    //色彩判断
    public static short colorJudge4(int colors){
        if (colors == 0){return 1;}
        if (colors <= 2) { return 2; }
        if (colors <= 5){ return 3; }
        if (colors <= 10){ return 4; }
        if (colors <= 15){ return 5; }
        if (colors <= 20){ return 6; }
        if (colors <= 50){ return 7; }
        if (colors <= 100){ return 8; }
        if (colors <= 200){ return 9; }
        return -1;
    }
    //色彩判断
    public static short colorJudge23(double colors){
        if (colors <= -2){return 1;}
        if (colors <= -1.5) { return 2; }
        if (colors <= -1.0){ return 3; }
        if (colors <= -0.5){ return 4; }
        if (colors <= 0){ return 5; }
        if (colors <= 0.5){ return 6; }
        if (colors <= 1.0){ return 7; }
        if (colors <= 1.5){ return 8; }
        if (colors <= 2){ return 9; }
        return -1;
    }
    //色彩判断
    public static short colorJudge6(int colors){
        if (colors == 0){return 1;}
        if (colors <= 20) { return 2; }
        if (colors <= 50){ return 3; }
        if (colors <= 100){ return 4; }
        if (colors <= 150){ return 5; }
        if (colors <= 200){ return 6; }
        if (colors <= 250){ return 7; }
        if (colors <= 300){ return 8; }
        if (colors <= 350){ return 9; }
        if (colors <= 400){ return 10; }
        if (colors <= 600){ return 11; }
        if (colors <= 800){ return 12; }
        if (colors <= 1000){ return 13; }
        return -1;
    }
    //倍数判断
    public static int isMultiple(Integer dttp){
        switch (dttp){
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
            case 8:
                return 100;
            case 1101:
                return 1000000;
            default:
                return -1;
        }
    }
    //色彩判断
    public static short colorJudge1101(double colors){
        System.out.println(colors);
        if (colors < 0.15){return 16;}
        if (colors < 0.30) { return 15; }
        if (colors < 0.45){ return 14; }
        if (colors < 0.60){ return 13; }
        if (colors < 0.75){ return 12; }
        if (colors < 0.90){ return 11; }
        if (colors < 1.05){ return 10; }
        if (colors < 1.20){ return 9; }
        if (colors < 1.35){ return 8; }
        if (colors < 1.50){ return 7; }
        if (colors < 1.65){ return 6; }
        if (colors < 1.80){ return 5; }
        if (colors < 1.95){ return 4; }
        if (colors < 2.10){ return 3; }
        if (colors < 2.25){ return 2; }
        if (colors >= 2.25 ){ return 1; }
        return -1;
    }

    /**
     * 风险等级判断
     * @param dttp 特征类型
     * @param calParaInfo 结果
     * @return
     */
    public static CalParaInfo riskLevelJudge(String dttp, CalParaInfo calParaInfo,String typeofpier){
        double value = 0.0;
        switch (dttp){
            case "桥墩":
                value = Double.parseDouble(calParaInfo.getHB());
                switch (typeofpier){
                    case "非通航孔桥墩1":
                    case "江海航道桥主墩":
//                        if (value < 7.19 ) {
//                            calParaInfo.setRiskLevel("一般风险1级");
//                            calParaInfo.setRiskColor("255,255,255");
//                        }else if (value >= 7.19 && value < 10.79) {
//                            calParaInfo.setRiskLevel("较大风险2级");
//                            calParaInfo.setRiskColor("255,255,0");
//                        }else if (value >= 10.79 && value < 11.99) {
//                            calParaInfo.setRiskLevel("重大风险3级");
//                            calParaInfo.setRiskColor("255,97,0");
//                        }else if (value >= 11.99    ) {
//                            calParaInfo.setRiskLevel("特大风险4级");
//                            calParaInfo.setRiskColor("255,0,0");
//                        }
                        if (value < 0 ) {
                            calParaInfo.setRiskLevel("一般风险1级");
                            calParaInfo.setRiskColor("255,255,255");
                        }else if (value >= 0 && value < 1.5) {
                            calParaInfo.setRiskLevel("较大风险2级");
                            calParaInfo.setRiskColor("255,255,0");
                        }else if (value >= 1.5 && value < 1.8) {
                            calParaInfo.setRiskLevel("重大风险3级");
                            calParaInfo.setRiskColor("255,97,0");
                        }else if (value >= 1.8    ) {
                            calParaInfo.setRiskLevel("特大风险4级");
                            calParaInfo.setRiskColor("255,0,0");
                        }
                    break;
                    case "非通航孔桥墩2":
//                        if (value < 7.13 ) {
//                            calParaInfo.setRiskLevel("一般风险1级");
//                            calParaInfo.setRiskColor("255,255,255");
//                        }else if (value >= 7.13 && value < 10.69) {
//                            calParaInfo.setRiskLevel("较大风险2级");
//                            calParaInfo.setRiskColor("255,255,0");
//                        }else if (value >= 10.69 && value < 11.88) {
//                            calParaInfo.setRiskLevel("重大风险3级");
//                            calParaInfo.setRiskColor("255,97,0");
//                        }else if (value >= 11.88) {
//                            calParaInfo.setRiskLevel("特大风险4级");
//                            calParaInfo.setRiskColor("255,0,0");
//                        }
                        if (value < 0 ) {
                            calParaInfo.setRiskLevel("一般风险1级");
                            calParaInfo.setRiskColor("255,255,255");
                        }else if (value >= 0 && value < 1.5) {
                            calParaInfo.setRiskLevel("较大风险2级");
                            calParaInfo.setRiskColor("255,255,0");
                        }else if (value >= 1.5 && value < 1.8) {
                            calParaInfo.setRiskLevel("重大风险3级");
                            calParaInfo.setRiskColor("255,97,0");
                        }else if (value >= 1.8    ) {
                            calParaInfo.setRiskLevel("特大风险4级");
                            calParaInfo.setRiskColor("255,0,0");
                        }
                        break;
                    case "九州航道桥主墩":
                        if (value < 6.6 ) {
                            calParaInfo.setRiskLevel("一般风险1级");
                            calParaInfo.setRiskColor("255,255,255");
                        }else if (value >= 6.6 && value < 9.9) {
                            calParaInfo.setRiskLevel("较大风险2级");
                            calParaInfo.setRiskColor("255,255,0");
                        }else if (value >= 9.9 && value < 11) {
                            calParaInfo.setRiskLevel("重大风险3级");
                            calParaInfo.setRiskColor("255,97,0");
                        }else if (value >= 11) {
                            calParaInfo.setRiskLevel("特大风险4级");
                            calParaInfo.setRiskColor("255,0,0");
                        }
                        break;
                    case "青州航道桥过渡墩":
                        if (value < 6.2 ) {
                            calParaInfo.setRiskLevel("一般风险1级");
                            calParaInfo.setRiskColor("255,255,255");
                        }else if (value >= 6.2 && value < 9.31) {
                            calParaInfo.setRiskLevel("较大风险2级");
                            calParaInfo.setRiskColor("255,255,0");
                        }else if (value >= 9.31 && value < 10.34) {
                            calParaInfo.setRiskLevel("重大风险3级");
                            calParaInfo.setRiskColor("255,97,0");
                        }else if (value >= 10.34) {
                            calParaInfo.setRiskLevel("特大风险4级");
                            calParaInfo.setRiskColor("255,0,0");
                        }
                        break;
                    case "青州航道桥主墩":
                        if (value < 9.64 ) {
                            calParaInfo.setRiskLevel("一般风险1级");
                            calParaInfo.setRiskColor("255,255,255");
                        }else if (value >= 9.64 && value < 14.45) {
                            calParaInfo.setRiskLevel("较大风险2级");
                            calParaInfo.setRiskColor("255,255,0");
                        }else if (value >= 14.45 && value < 16.06) {
                            calParaInfo.setRiskLevel("重大风险3级");
                            calParaInfo.setRiskColor("255,97,0");
                        }else if (value >= 16.06) {
                            calParaInfo.setRiskLevel("特大风险4级");
                            calParaInfo.setRiskColor("255,0,0");
                        }
                        break;
                    default:
                        break;
                }
                break;
            case "沉管":
                value = Double.parseDouble(calParaInfo.getErosionAndSiltationAssessment());
//                if (value < 9.64 ) {
//                    calParaInfo.setRiskLevel("一般风险1级");
//                    calParaInfo.setRiskColor("255,255,255");
//                }else if (value >= 9.64 && value < 14.45) {
//                    calParaInfo.setRiskLevel("较大风险2级");
//                    calParaInfo.setRiskColor("255,255,0");
//                }else if (value >= 14.45 && value < 16.06) {
//                    calParaInfo.setRiskLevel("重大风险3级");
//                    calParaInfo.setRiskColor("255,97,0");
//                }else if (value >= 16.06) {
//                    calParaInfo.setRiskLevel("特大风险4级");
//                    calParaInfo.setRiskColor("255,0,0");
//                }
                if (value < 0 ) {
                    calParaInfo.setRiskLevel("一般风险1级");
                    calParaInfo.setRiskColor("255,255,255");
                }else if (value >= 0 && value < 1.5) {
                    calParaInfo.setRiskLevel("较大风险2级");
                    calParaInfo.setRiskColor("255,255,0");
                }else if (value >= 1.5 && value < 1.8) {
                    calParaInfo.setRiskLevel("重大风险3级");
                    calParaInfo.setRiskColor("255,97,0");
                }else if (value >= 1.8    ) {
                    calParaInfo.setRiskLevel("特大风险4级");
                    calParaInfo.setRiskColor("255,0,0");
                }
                break;
            case "填充岛屿":
//                double fv = Double.parseDouble(calParaInfo.getFV());
//                double fh = Double.parseDouble(calParaInfo.getFH());
                calParaInfo.setRiskLevelFH("一般风险1级");
                calParaInfo.setRiskColorFH("255,255,255");
                calParaInfo.setRiskLevelFV("一般风险1级");
                calParaInfo.setRiskColorFV("255,255,255");
                break;
            default:
                break;
        }
        return calParaInfo;
    }

    public static short colorJudge(String s, List<ColourInfo> colourInfos){
        double i = Double.parseDouble(s) / 100;
        if (i >= Double.parseDouble(colourInfos.get(0).getScope())) {
            return 1;
        }else if (i < Double.parseDouble(colourInfos.get(0).getScope()) &&
                i >= Double.parseDouble(colourInfos.get(1).getScope().split(",")[1])) {
            return 2;
        }else if (i < Double.parseDouble(colourInfos.get(1).getScope().split(",")[1]) &&
                i >= Double.parseDouble(colourInfos.get(2).getScope().split(",")[1])) {
            return 3;
        }else if (i < Double.parseDouble(colourInfos.get(2).getScope().split(",")[1]) &&
                i >= Double.parseDouble(colourInfos.get(3).getScope().split(",")[1])) {
            return 4;
        }else if (i < Double.parseDouble(colourInfos.get(3).getScope().split(",")[1]) &&
                i >= Double.parseDouble(colourInfos.get(4).getScope().split(",")[1])) {
            return 5;
        }else if (i < Double.parseDouble(colourInfos.get(4).getScope().split(",")[1]) &&
                i >= Double.parseDouble(colourInfos.get(5).getScope().split(",")[1])) {
            return 6;
        }else if (i < Double.parseDouble(colourInfos.get(5).getScope().split(",")[1]) &&
                i >= Double.parseDouble(colourInfos.get(6).getScope().split(",")[1])) {
            return 7;
        }else if (i < Double.parseDouble(colourInfos.get(6).getScope().split(",")[1]) &&
                i >= Double.parseDouble(colourInfos.get(7).getScope().split(",")[1])) {
            return 8;
        }else if (i < Double.parseDouble(colourInfos.get(7).getScope().split(",")[1]) &&
                i >= Double.parseDouble(colourInfos.get(8).getScope().split(",")[1])) {
            return 9;
        }else if (i < Double.parseDouble(colourInfos.get(8).getScope().split(",")[1]) &&
                i >= Double.parseDouble(colourInfos.get(9).getScope().split(",")[1])) {
            return 10;
        }else if (i < Double.parseDouble(colourInfos.get(9).getScope().split(",")[1]) &&
                i >= Double.parseDouble(colourInfos.get(10).getScope().split(",")[1])) {
            return 11;
        }else if (i < Double.parseDouble(colourInfos.get(10).getScope().split(",")[1]) &&
                i >= Double.parseDouble(colourInfos.get(11).getScope().split(",")[1])) {
            return 12;
        }else if (i < Double.parseDouble(colourInfos.get(11).getScope().split(",")[1]) &&
                i >= Double.parseDouble(colourInfos.get(12).getScope().split(",")[1])) {
            return 13;
        }else if (i < Double.parseDouble(colourInfos.get(12).getScope().split(",")[1]) &&
                i >= Double.parseDouble(colourInfos.get(13).getScope().split(",")[1])) {
            return 14;
        }else {
            return 15;
        }
    }

}
